package com.house.java.dao;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.house.java.dao.impl.HouseSurroundDaoImpl;
import com.house.java.dao.impl.NewHouseDaoImpl;
import com.house.java.dao.impl.NewsDaoImpl;
import com.house.java.dao.impl.PriceHistoryDaoImpl;
import com.house.java.dao.impl.SecondHouseDaoImpl;
import com.house.java.dao.impl.UserDaoImpl;

public class DaoFactory {
	
	private static Map<Class, Class> daofactory = new HashMap<Class, Class>();
	private static Logger log = Logger.getLogger(DaoFactory.class);
	static{
		daofactory.put(NewHouseDAO.class, NewHouseDaoImpl.class);
		daofactory.put(SecondHouseDAO.class, SecondHouseDaoImpl.class);
		daofactory.put(HouseSurroundDAO.class, HouseSurroundDaoImpl.class);
		daofactory.put(PriceHistoryDAO.class, PriceHistoryDaoImpl.class);
		daofactory.put(NewsDAO.class, NewsDaoImpl.class);
		daofactory.put(UserDAO.class, UserDaoImpl.class);
	}

	public static Object getDaoImpl(Class classes){
		try {
			return daofactory.get(classes).newInstance();
		} catch (InstantiationException e) {
			log.error(e.getMessage());
		} catch (IllegalAccessException e) {
			log.error(e.getMessage());
		}
		return null;
	}
}
